package xmlparser;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import docks.Dock;

public class SaxParser {

    private String xml;
    private Hashtable<Integer, Dock> dockList;

    public SaxParser(String xml) {

	this.xml = xml;
    }

    public void parseBicingState() throws ParserConfigurationException,
	    SAXException, IOException {

	SAXParserFactory spf = SAXParserFactory.newInstance();
	SAXParser sp = spf.newSAXParser();
	XMLReader xr = sp.getXMLReader();

	BicingHandler bh = new BicingHandler();
	xr.setContentHandler(bh);
	
	ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes());
	InputSource source = new InputSource(in);
	xr.parse( source );

	dockList = bh.dockList;

    }

    public String getXml() {
	return xml;
    }

    public void setXml(String xml) {
	this.xml = xml;
    }

    public Hashtable<Integer, Dock> getDockList() {
	return dockList;
    }

    public void setDockList(Hashtable<Integer, Dock> dockList) {
	this.dockList = dockList;
    }
}
